package demo1;

import javax.swing.*;
import java.awt.*;

public class Test2 {
    public static void main1(String[] args) {
        JFrame window1  = new JFrame("一个窗口");
        Container con = window1.getContentPane() ;
        con.setBackground(Color.yellow);
        window1.setBounds(500 , 50 , 400 , 200);
        window1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window1.setVisible(true);
    }

    public static void main(String[] args) {
        WindowMenu windowMenu = new WindowMenu("带菜单的窗口" ,20 ,
                30 , 1000 , 1000) ;
    }


}

class WindowMenu extends JFrame{
    JMenuBar menubar ;
    JMenu menuFruit ;
    JMenuItem bananaItem , pearItem ;
    JMenu appleMenu ;
    JMenuItem redAppleItem ;
    public WindowMenu() {};
    public WindowMenu(String s ,int x , int y , int w , int h){
       this.init(s);
       this.setLocation(x , y);
       this.setSize(w,h);
       this.setVisible(true);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(String s){
        this.setTitle(s);
        this.menubar = new JMenuBar() ;
        this.menuFruit = new JMenu("水果菜单") ;
        this.bananaItem = new JMenuItem("香蕉") ;
        this.bananaItem.setIcon(new ImageIcon("F:\\word\\java_yan\\j2023_11_7\\src\\demo1\\banana.jpg"));
        this.pearItem = new JMenuItem("梨子");
        this.pearItem.setIcon(new ImageIcon("F:\\word\\java_yan\\j2023_11_7\\src\\demo1\\pear.jpg")) ;
        this.appleMenu = new JMenu("苹果") ;
        this.redAppleItem = new JMenuItem("红苹果") ;
        this.redAppleItem.setIcon(new ImageIcon("F:\\word\\java_yan\\j2023_11_7\\src\\demo1\\apple.jpg"));

        this.menuFruit.add(bananaItem) ;
        this.menuFruit.add(pearItem) ;
        this.menuFruit.add(appleMenu) ;
        this.appleMenu.add(redAppleItem) ;
        this.menubar.add(menuFruit) ;
        this.setJMenuBar(menubar);
    }

}
